package com.iptv.grape;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import com.iptv.grape.event.EventArgs;

import com.iptv.grape.net.NetworkService;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.util.ReadJsonFile;

import java.util.Date;

public class TestActivity extends AppCompatActivity {

    private TextView tvShow;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        tvShow = this.findViewById(R.id.tv_show);

        tvShow.setMovementMethod(ScrollingMovementMethod.getInstance());
        Button button = this.findViewById(R.id.btnType);
        button.setOnClickListener(new BtnCilckListener());

        Button btnRunImg = this.findViewById(R.id.btnRunImg);
        btnRunImg.setOnClickListener(new BtnCilckListener());

        Button btnChannel = this.findViewById(R.id.btnChannel);
        btnChannel.setOnClickListener(new BtnCilckListener());

        Button btnReadJson = this.findViewById(R.id.btnReadJson);
        btnReadJson.setOnClickListener(new BtnCilckListener());

        Button btnConfig = this.findViewById(R.id.btnConfig);
        btnConfig.setOnClickListener(new BtnCilckListener());

        Button btnlogin = this.findViewById(R.id.btnlogin);
        btnlogin.setOnClickListener(new BtnCilckListener());

        Button btnSendTTL = this.findViewById(R.id.btnSendTTL);
        btnSendTTL.setOnClickListener(new BtnCilckListener());

        Button btnBillList = this.findViewById(R.id.btnBillList);
        btnBillList.setOnClickListener(new BtnCilckListener());

        EventBus.getDefault().register(this);
        String json = ReadJsonFile.readFileByAssets("stbBaseConfig.json",TestActivity.this);
        ReadJsonFile.writeFile("stbBaseConfig.json",json);
        //this.WriteFile(json);

    }



    // 消息处理
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMoonEvent(EventArgs eventArgs){
        AppLog.getCurLog().out("TestActivity----onMoonEvent");
        if(eventArgs.getEventType().equals("NetworkService") && eventArgs.getIsExistsArgs()) {
            tvShow.setText(eventArgs.getJson());

            //ChannelResult result = (ChannelResult)eventArgs.getEventArgs();
            //if()
            //List<ChannelData> list = result.getData().getChannelList();
            //Log.d("111", "111: ");

        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //取消注册事件
        EventBus.getDefault().unregister(this);
    }

    // 内部类
    class BtnCilckListener implements View.OnClickListener{


        @Override
        public void onClick(View v){
            if(v.getId() == R.id.btnBillList){
                NetworkService.getInstance().getChannelListDetailsByDate(new Date());
            }
            if(v.getId() == R.id.btnType){
                NetworkService.getInstance().getChannelTypeList();
            }
            if(v.getId() == R.id.btnChannel){
                NetworkService.getInstance().getChannelList();
            }
            if(v.getId() == R.id.btnRunImg){
                NetworkService.getInstance().getAppRunimg();
            }
            if(v.getId() == R.id.btnConfig){
                NetworkService.getInstance().getConfigList();
            }
            if(v.getId() == R.id.btnlogin){
                NetworkService.getInstance().login();
            }
            if(v.getId() == R.id.btnSendTTL){
                NetworkService.getInstance().sendTTL();
            }
            if(v.getId() == R.id.btnReadJson){
                //String json = ReadJsonFile.readFileByAssets("stbBaseConfig.json",TestActivity.this);
                //tvShow.setText(TestActivity.this.ReadFile());

                tvShow.setText(ReadJsonFile.readFile("stbBaseConfig.json",TestActivity.this));
                //tvShow.setText(ReadJsonFile.readFile("stbBaseConfig.json"));
                //tvShow.setText(json);

            }
        }
    }


}
//%ERLANG_HOME%\bin;
//%JAVA_XPATH%;%MPI_PATH%;%RSA_PATH%;%ORACLE_PATH1%\bin;%ORACLE_PATH2%\bin;%ORACLE_PATH3%\bin;c:\program files (x86)\amd app\bin\x86_64;c:\program files (x86)\amd app\bin\x86;c:\program files\common files\microsoft shared\windows live;c:\program files (x86)\common files\microsoft shared\windows live;%systemroot%\system32;%systemroot%;%systemroot%\system32\wbem;%systemroot%\system32\windowspowershell\v1.0\;c:\program files\intel\wifi\bin\;c:\program files\common files\intel\wirelesscommon\;c:\program files (x86)\ati technologies\ati.ace\core-static;c:\program files (x86)\windows live\shared;c:\program files (x86)\microsoft sql server\90\tools\binn\;c:\program files\microsoft\web platform installer\;c:\program files\tortoisesvn\bin;c:\program files\ibm\gsk8\lib64;c:\program files (x86)\ibm\gsk8\lib;C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\FUNCTION;C:\PROGRA~1\IBM\SQLLIB\SAMPLES\REPL;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\VisualSVN\bin;C:\PSTools;C:\Program Files\OpenVPN\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\MongoDB\Server\3.2\bin;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Python27\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;C:\Program Files\Redis;C:\Program Files\PuTTY\;C:\Go\bin
//%JAVA_XPATH%;%MPI_PATH%;%RSA_PATH%;%ORACLE_PATH1%\bin;%ORACLE_PATH2%\bin;%ORACLE_PATH3%\bin;%AMD_PATH%\bin\x86_64;%AMD_PATH%\bin\x86;%WLIVE_PATH%;c:\program files (x86)\common files\microsoft shared\windows live;%systemroot%\system32;%systemroot%;%systemroot%\system32\wbem;%systemroot%\system32\windowspowershell\v1.0\;c:\program files\intel\wifi\bin\;c:\program files\common files\intel\wirelesscommon\;c:\program files (x86)\ati technologies\ati.ace\core-static;c:\program files (x86)\windows live\shared;c:\program files (x86)\microsoft sql server\90\tools\binn\;c:\program files\microsoft\web platform installer\;c:\program files\tortoisesvn\bin;c:\program files\ibm\gsk8\lib64;c:\program files (x86)\ibm\gsk8\lib;C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\FUNCTION;C:\PROGRA~1\IBM\SQLLIB\SAMPLES\REPL;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\VisualSVN\bin;C:\PSTools;C:\Program Files\OpenVPN\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\MongoDB\Server\3.2\bin;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Python27\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;%ERLANG_HOME%\bin;C:\Program Files\Redis;C:\Program Files\PuTTY\;C:\Go\bin;C:\Program Files (x86)\Android\android-sdk\platform-tools;
//C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\RSA SecurID Token Common;f:\oracle\product\11.2.0\client_1\bin;f:\oracle\product\11.2.0\dbhome_1\bin;f:\oracle\product\10.2.0\client_1\bin;c:\program files (x86)\amd app\bin\x86_64;c:\program files (x86)\amd app\bin\x86;c:\program files\common files\microsoft shared\windows live;c:\program files (x86)\common files\microsoft shared\windows live;%systemroot%\system32;%systemroot%;%systemroot%\system32\wbem;%systemroot%\system32\windowspowershell\v1.0\;c:\program files\intel\wifi\bin\;c:\program files\common files\intel\wirelesscommon\;c:\program files (x86)\ati technologies\ati.ace\core-static;c:\program files (x86)\windows live\shared;c:\program files (x86)\microsoft sql server\90\tools\binn\;c:\program files\microsoft\web platform installer\;c:\program files\tortoisesvn\bin;c:\program files\ibm\gsk8\lib64;c:\program files (x86)\ibm\gsk8\lib;C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\FUNCTION;C:\PROGRA~1\IBM\SQLLIB\SAMPLES\REPL;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\VisualSVN\bin;C:\PSTools;C:\Program Files\OpenVPN\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\MongoDB\Server\3.2\bin;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Python27\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;%ERLANG_
//C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\RSA SecurID Token Common;f:\oracle\product\11.2.0\client_1\bin;f:\oracle\product\11.2.0\dbhome_1\bin;f:\oracle\product\10.2.0\client_1\bin;c:\program files (x86)\amd app\bin\x86_64;c:\program files (x86)\amd app\bin\x86;c:\program files\common files\microsoft shared\windows live;c:\program files (x86)\common files\microsoft shared\windows live;%systemroot%\system32;%systemroot%;%systemroot%\system32\wbem;%systemroot%\system32\windowspowershell\v1.0\;c:\program files\intel\wifi\bin\;c:\program files\common files\intel\wirelesscommon\;c:\program files (x86)\ati technologies\ati.ace\core-static;c:\program files (x86)\windows live\shared;c:\program files (x86)\microsoft sql server\90\tools\binn\;c:\program files\microsoft\web platform installer\;c:\program files\tortoisesvn\bin;c:\program files\ibm\gsk8\lib64;c:\program files (x86)\ibm\gsk8\lib;C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\FUNCTION;C:\PROGRA~1\IBM\SQLLIB\SAMPLES\REPL;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\VisualSVN\bin;C:\PSTools;C:\Program Files\OpenVPN\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\MongoDB\Server\3.2\bin;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Python27\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;C:\Progr
// C:\Program Files (x86)\Android\android-sdk\platform-tools